<!DOCTYPE html>
<html lang="en">

<head>
    <title>单例模式</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
    <script>
        var Conf = (function () {
            //私有变量
            var conf = {
                MAX_NUM: 100,
                MIN_NUM: 1,
                COUNT: 1000
            };
            //返回取值器对象
            return {
                //取值器方法
                get: function (name) {
                    return conf[name] ? conf[name] : null;
                }
            };
        })();
        var count = Conf.get('COUNT');
        //惰性载入单例
        var LazySingle = (function () {
            //单例实例引用
            var _instance = null;
            //单例
            function Single() {
                return {
                    //定义私用属性和方法
                    publicMethod: function () {},
                    publicProperty: '1.0'
                }
            }
            //获取单例对象接口
            return function () {
                if (!_instance) {
                    _instance = Single();
                }
                //返回单例
                return _instance;
            }
        })();
        console.log(LazySingle().publicProperty);
    </script>
</body>

</html>